function render(aid, list) {
  let oBody = document.querySelector('tbody')
  for (let i in list) {
    let track = list[i]
    let html = `          <tr>
            <td>${track.tid}</td>
            <td>${track.title}</td>
            <td><a href="/studio/album/unbind.do?aid=${aid}&tid=${track.tid}">取消关联</a></td>
          </tr>`
    oBody.innerHTML += html
  }
}

window.addEventListener('load', function () {
  let aid = getParameter("aid")
  if (isNaN(aid)) {
    alert("url 中没有 aid 或者 aid 不是数字")
    return
  }

  document.querySelector("#add").href = '/studio/album/add.html?aid=' + aid

  let xhr = new XMLHttpRequest()
  xhr.open('get', '/studio/album/relate.json?aid=' + aid)
  xhr.addEventListener('load', function () {
    console.log(xhr.responseText)
    let data = JSON.parse(this.responseText)
    renderCurrentUser(data.currentUser)
    if (data.trackList) {
      render(aid, data.trackList)
    }
  })
  xhr.send()
})